package cn.itcast.com.homework.day813;

import java.util.ArrayList;

/*
3  使用ArrayList来实现一个栈的数据结构（先进后出），要求 实现pop() ，push(E e), peek() , isEmpty()等基本操作。使用泛型更好。
 */
public class test {
    public static void main(String[] args) {
        ArrayList<Object> objects = new ArrayList<>();
        objects.isEmpty();
        aStack aStack = new aStack();
        aStack.push("A");
        aStack.push("B");
        aStack.push("C");
        System.out.println("初始的栈中数据：" + aStack);
        System.out.println("pop "+aStack.pop());
        System.out.println("执行pop之后的栈中数据：" + aStack);
        System.out.println("peek "+aStack.peek());
        System.out.println("执行peek之后的栈中数据：" + aStack);
        System.out.println("isEmpty "+aStack.isEmpty());
        System.out.println("执行isEmpty之后的栈中数据：" + aStack);
    }

}

class aStack extends ArrayList{
    public Object pop(){
        int size = this.size();
        Object remove = this.remove(size - 1);
        return remove;
    }

    public boolean push(Object o){
        boolean add = this.add(o);
        return add;
    }

    public Object peek(){
        int size = this.size();
        Object o = this.get(size - 1);
        return o;
    }

    public boolean isEmpty(){
        if (this.size() == 0){
            return true;
        }else {
            return false;
        }
    }
}
